

//格式化按钮
var optionFormatter = function(value, row, index) {
	return `<div class="dropdown">
  <button class="btn btn-outline-primary btn-block dropdown-toggle" type="button" data-toggle="dropdown">
    操作
  </button>
  <div class="dropdown-menu dropdown-menu-right">
    <a class="dropdown-item _delete" data-index="${index}" href="javascript:void(0);">删除</a>

<a class="dropdown-item _update" data-index="${index}" href="javascript:void(0);">重置密码</a>
  </div>
</div>`;
}

var searchForm = $(document.forms.searchForm);
var sysRoleId = $(document.forms.searchForm.sysRoleId);
$.get(
	"admin/user.let?action=listRole",
	function(data){
		for(let role of data) {
			sysRoleId.append(`<option value="${role.sysRoleid}">${role.sysRoleName}</option>`);
		
		}
	},"json"
);
//保存条件

var searchParams = new URLSearchParams();
searchForm.on("submit",function(){
	searchParams = sys.form.param(searchForm[0]);
	console.info(searchParams);
	datagrid.bootstrapTable("refresh",{pageNumber:1});
	return false;
});


var datagrid = $("#datagrid").bootstrapTable({
	url: "admin/user.let?action=page",
	dataField: "list",//rows
	totalField: "total",
	queryParamsType: "",//limit
	pagination: true,
	sidePagination: "server",//client
	queryParams:function(params) { 
	  for(let name of searchParams.keys()){//添加搜索条件
		 console.info(name+"="+searchParams.get(name));
		  params[name]=searchParams.get(name);


	  }

	 console.info(params);
	  return params ;
    }
});



//性别

var userSexFormatter= function(value,row,index,fieldName){
	return value=="男"?"男":"女";
}
//编号
var indexFormatter =function(value,row,index,fieldName){
	return index+1;
}
var adminFormatter=function(value,row,index,fieldName){
	return value==1?"管理员":"会员";
}



//href="admin/update.let?id=${value}
//data-index="${index}" href="javascript:void(0);

//    var confirmDialog=$("#confirmDialog");
//    $("._delete").on("click",function(){
//    	  confirmDialog.find("a:last").attr("href",$(this).attr("href"));
//    	    confirmDialog.modal("show");
//    	return false;
//    });



datagrid.on("click","._delete",function(){
      let obj=$(this);

	let index=obj.data("index");
	let row=datagrid.bootstrapTable("getData")[index];
	
	sys.confirm(`您确定删除[${row.hdlUserName}]吗`,function(r){
		if(r){
			$.post(	"admin/user.let?action=delete",
			{"hdlUserId":row.hdlUserId},
			function(data){
				if(data.code==200){
				sys.toastr.success(`您成功的删除了[${row.hdlUserName}]`);
				datagrid.bootstrapTable("refresh");
					} else {
					sys.toastr.error(data.message);
					}
				}, "json");
}
	});
}).on("click","._update",function(){
	let obj=$(this);
	let index =obj.data("index");
	let row =datagrid.bootstrapTable("getData")[index];
	sys.confirm(`您确定重置[${row.hdlUserName}]的密码吗？`,function(r){
		if(r){
			$.post("admin/user.let?action=updatePwd",{"hdlUserId":row.hdlUserId},function(data){
				if(data.code==200){
					sys.toastr.success(`您成功重置[${row.hdlUserName}]的密码`);
					datagrid.bootstrapTable("refresh");
					
					
				}else{
					sys.toastr.error(data.message);
				}
			},"json");
		}
	})
});




//var searchParams = new URLSearchParams();
//searchForm.on("submit",function(){
//	searchParams = sys.form.param(searchForm[0]);
//	datagrid.bootstrapTable("refresh",{pageNumber:1});
//	alert(111);
//	return false;
//});







































